package com.nexgo.payment.action.online.upload;

import com.nexgo.payment.App;
import com.nexgo.payment.R;
import com.nexgo.payment.constrant.TransType;
import com.nexgo.payment.databases.DataSource;
import com.nexgo.payment.databases.SettleInfo;
import com.nexgo.payment.databases.TransRecord;
import com.nexgo.payment.util.TransUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * Created by xiaox on 2017/9/5.
 */

/**
 * 批上送IC卡脱机拒绝交易
 */
class BatchUploadIccOfflineDeclined extends AbsBatchUpload {
    private final Logger log;
    private final SettleInfo mSettleInfo;
    private final List<TransRecord> mTransRecords;
    private int mIdx = 0;

    BatchUploadIccOfflineDeclined(DataSource repository) {
        super(repository);
        log = LoggerFactory.getLogger(getClass().getSimpleName());
        mTransRecords = mRepository.getIccOfflineDeclinedTransRecords();
        mSettleInfo = mRepository.getSettleInfo();
    }

    @Override
    TransType getTransType() {
        return TransType.BATCH_UPLOAD_ICC_OFFLINE_DECLINED;
    }

    @Override
    String getTip() {
        return App.sContext.getString(R.string.batch_upload_icc);
    }

    @Override
    TransRecord hasNext() {
        for (int i = mIdx; i < mTransRecords.size(); i++) {
            TransRecord transRecord = mTransRecords.get(i);
            //批上送成功的跳过
            if (transRecord.getIsBatchUpload()) {
                continue;
            }
            //内卡对帐平跳过
            if (mSettleInfo.getIsEqu() && !transRecord.getIsInternational()) {
                continue;
            }
            //外卡对帐平跳过
            if (mSettleInfo.getIsInterEqu() && transRecord.getIsInternational()) {
                continue;
            }
            //lr add扫码交易跳过
            TransType transType = TransType.values()[transRecord.getTransType()];
            if(TransUtils.isScanTrans(transType)){
                continue;
            }

            //不是IC卡跳过
            if (!TransUtils.isICCTransByEntryMode(transRecord.getEntryMode())) {
                continue;
            }
            mIdx = i + 1;
            return transRecord;
        }
        return null;
    }
}
